/*
 * Copyright (C) 2010-2012  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#include "etypes.h"

#ifndef _emath_h
#define _emath_h

#define eadd_over_p(u, v, w)		((w) >= 0 ? (u) < (v) : (u) > (v))
#define esub_over_p(u, v, w)		((w) >= 0 ? (u) > (v) : (u) < (v))

#define thr_qq				&thread_self->qq
#define thr_qr				cqq_realref(thr_qq)
#define thr_qi				cqq_imagref(thr_qq)
#define thr_zr				mpq_numref(thr_qr)
#define thr_zs				mpq_denref(thr_qr)
#define thr_cc				&thread_self->cc
#define thr_rr				mpc_realref(thr_cc)
#define thr_ri				mpc_imagref(thr_cc)

#define thr_prc				mpfr_get_default_prec()
#define thr_rnd				MPFR_RNDN
#define thr_rndc			MPC_RNDNN

/*
 * Prototypes
 */
#if __WORDSIZE == 32
extern eint64_t
empz_get_ll(empz_t z);

extern void
empz_set_ll(empz_t z, eint64_t u);

extern void
empz_set_ull(empz_t z, euint64_t u);
#else
#  define empz_get_ll(z)		mpz_get_si(z)
#  define empz_set_ll(z, u)		mpz_set_si(z, u)
#  define empz_set_ull(z, u)		mpz_set_ui(z, u)
#endif

extern eint64_t
empq_get_ll(empq_t q);

extern eint64_t
empr_get_ll(empr_t r);

extern eword_t
ew_mul_w_w(eword_t a, eword_t b);

#endif /* _emath_h */
